package com.jdk.demo.fileChannel.positionWrite;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Test7_3 {
	
	// 验证write方法中position的不变性
	public static void main(String[] args) throws Exception {
		FileOutputStream fosRef = new FileOutputStream(new File("g.txt"));
		FileChannel fileChannel = fosRef.getChannel();
		
		System.out.println("A position=" + fileChannel.position());
		fileChannel.position(3);
		System.out.println("B position=" + fileChannel.position());
		
		fileChannel.write(ByteBuffer.wrap("abcde".getBytes()), 0);
		System.out.println("C position=" + fileChannel.position());
		
		// 程序运行后，position不改变，依然还是3
		fosRef.close();
		fileChannel.close();
	}

}
